package com.bmw.seed.test;

import com.bmw.seed.SeedApplication;
import com.bmw.seed.service.UserRegistInfoService;
import com.bmw.seed.util.bean.RegisReq;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Classname: testUnique
 * Package: com.bmw.seed.test
 * Description:
 *
 * @Author 王少伟
 * @Create 2024/1/29 15:17
 * @Version 1.8
 */

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SeedApplication.class)
@Slf4j
public class testUnique {
    @Autowired
    private UserRegistInfoService userRegistInfoService;
    @Test
    public void testUnique() throws InterruptedException{
        //创建使用单个线程的线程池
        ExecutorService es = Executors.newFixedThreadPool(2);
        //使用lambda实现runnable接口
        Runnable task = ()->{
            RegisReq req = new RegisReq();
            req.setPhone("12345678312");
            req.setPassword("123456a");
            Long id = userRegistInfoService.unique(req);
            log.info(Thread.currentThread().getName()+ "创建了一个新的线程执行" + id);

        };
        //调用submit传递线程任务，开启线程
        es.submit(task);
        es.submit(task);

        //当线程守护停止后，子线程就不运行了，在项目正常启动中，项目一致运行，不需要加
        Thread.sleep(10000);

    }

}
